package com.hanliukui.ai.langchain4j.assistant.xiaozhi.business;


import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class XiaoziAppointmentService {

    private final AppointmentRepository appointmentRepository;

    public XiaoziAppointmentService(AppointmentRepository appointmentRepository) {
        this.appointmentRepository = appointmentRepository;
    }

    public List<AppointmentPo> queryUserAppointments(String idCard) {
        return appointmentRepository.findByIdCard(idCard);
    }

    public AppointmentPo getAppointment(AppointmentPo appointment) {
        return appointmentRepository.findByIdCardAndDepartmentAndDateAndTime(appointment.getIdCard(), appointment.getDepartment(), appointment.getDate(), appointment.getTime());
    }

    public AppointmentPo createAppointment(AppointmentPo appointment) {
        return appointmentRepository.save(appointment);
    }

    public AppointmentPo updateAppointment(AppointmentPo appointment) {
        return appointmentRepository.save(appointment);
    }

    public String cancelAppointment(AppointmentPo appointment) {
        AppointmentPo existingAppointment = getAppointment(appointment);
        if (existingAppointment != null) {
            appointmentRepository.delete(existingAppointment);
            return "取消预约成功";
        } else {
            return "用户没有预约信息";
        }
    }
}

